package com.android.tea;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.android.tea.adapter.FriendsRequestAdapter;
import com.android.tea.entity.NotifyInfo;

public class FriendsRequestActivity extends Activity implements OnClickListener{
	private Button btnBack;
	private Button btnDel;
	private ListView listView;
	private FriendsRequestAdapter adapter;
	private List<NotifyInfo> loadData;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.friends_request);
	
		initComponents();
	}

	private void initComponents() {
		btnBack = (Button)findViewById(R.id.btn_back);
		btnBack.setOnClickListener(this);
		btnDel = (Button)findViewById(R.id.btn_delete);
	
		btnDel.setOnClickListener(this);
		
		listView = (ListView)findViewById(R.id.listView1);
		listView.setCacheColorHint(Color.TRANSPARENT);
//		Bitmap bitmap = Bitmap.createBitmap(new int[] { 0xFFDEDEDE, 0xFFDEDEDE, 0xFFDEDEDE, 0xFFDEDEDE, 0xFFFFFFFF,
//				0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }, 2, 4, Config.RGB_565);
//		listView.setDivider(new BitmapDrawable(bitmap));
//		listView.setDividerHeight(2);
		loadData = loadData();
		adapter = new FriendsRequestAdapter(this,loadData);
		listView.setAdapter(adapter);
	}

	private List<NotifyInfo> loadData() {
		List<NotifyInfo> list = new ArrayList<NotifyInfo>();
		NotifyInfo member4 = new NotifyInfo();
//		member.setAvatar(avatar);
		member4.setTitle("善良的灰太狼");
		member4.setDesc("一起去shopping?");
		member4.setTimeStamp(System.currentTimeMillis());
		list.add(member4);
		
		NotifyInfo member = new NotifyInfo();
//		member.setAvatar(avatar);
		member.setTitle("茶百科团队");
		member.setDesc("谢谢你的反馈");
		member.setTimeStamp(System.currentTimeMillis());
		list.add(member);
		
		return list;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			super.onBackPressed();
			break;
		case R.id.btn_delete:
			//弹出popowindow
			new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.confirm_delete))
			.setPositiveButton(getResources().getString(R.string.confirm), new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					loadData.clear();
					adapter.notifyDataSetChanged();
				}
			}).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			}).show();

			break;

		default:
			break;
		}
		
	}
}
